package pub.gll.plugin.util;


import org.objectweb.asm.Type;

/**
 * @author: hujianqiang
 * @date: 2021/4/25
 */
public class CheckClass {
    public static boolean isSubClassWithRulesAndIsNotSelf(String className) {
        return (ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseModule")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseMvpPresent")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseMvpView")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseDataProvider")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseDataRepository")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.base.BaseMainController")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.action.BaseArchView")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.rv.BaseArchViewHolder")
                || ClassUtil.isSuper(className, "com.kuaikan.library.arch.rv.BaseArchHolderPresent")) && isNotWithRules(StringUtil.replaceSlash2Dot(className));

    }

    private static boolean isNotWithRules(String className) {
        return !className.equals("com.kuaikan.library.arch.base.BaseModule")
                && !className.equals("com.kuaikan.library.arch.base.BaseMvpPresent")
                && !className.equals("com.kuaikan.library.arch.base.BaseMvpView")
                && !className.equals("com.kuaikan.library.arch.base.BaseDataProvider")
                && !className.equals("com.kuaikan.library.arch.base.BaseDataRepository")
                && !className.equals("com.kuaikan.library.arch.base.BaseMainController")
                && !className.equals("com.kuaikan.library.arch.action.BaseArchView")
                && !className.equals("com.kuaikan.library.arch.rv.BaseArchViewHolder")
                && !className.equals("com.kuaikan.library.arch.rv.BaseArchHolderPresent");
    }


    public static boolean isRulesAnnotation(String desc) {
        try {
            return Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindController")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindDataProvider")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindModule")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindMvpView")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindPresent")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindRepository")).getDescriptor().equals(desc);
        } catch (ClassNotFoundException e) {
           Log.w("CheckClass","工程中 没有找到指定注解 "+ e.getMessage());
        }
        return false;
    }

    public static boolean isNeedInterfaceTypeAnnotation(String desc) {
        try {
            return Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindModule")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindMvpView")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindPresent")).getDescriptor().equals(desc) ||
                    Type.getType(ClassUtil.getClass("com.kuaikan.annotation.arch.BindRepository")).getDescriptor().equals(desc);
        } catch (ClassNotFoundException e) {
            Log.w("CheckClass","工程中 没有找到指定注解 "+ e.getMessage());
        }
        return false;
    }

}
